<?php

 /* Jabberish - a multi-functional jabber bot
  * Copyright (C) 2006 Mark Walling <markwalling@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */

function prase_config_file() {
    include("config.inc.php");

}

function botaction_about_text($message) {
	global $j;
	$from = $j->GetInfoFromMessageFrom($message);

	$j->SendMessage($from, 'chat', null, array('body' => "Jabberish version 0.10, Copyright (C) 2006 Mark Walling\nJabberish comes with ABSOLUTELY NO WARRANTY; for details type `warranty'.\nThis is free software, and you are welcome to redistribute it under certain conditions; type `conditions' for details.\n\nWeather forcasts provided by Yahoo! Weather")) or die("SendMessage failed in ".__FILE__." on line ".__LINE__);
}

function botaction_warranty_text($message) {
	global $j;
	$from = $j->GetInfoFromMessageFrom($message);

	$j->SendMessage($from, 'chat', null, array('body' => "BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.")) or die("SendMessage failed in ".__FILE__." on line ".__LINE__);
}

function botaction_conditions_text($message) {
	global $j;
	$from = $j->GetInfoFromMessageFrom($message);

	$j->SendMessage($from, 'chat', null, array('body' => "Conditions of Redistribution can be found in the GNU GPL at http://gnu.org/")) or die("SendMessage failed in ".__FILE__." on line ".__LINE__);
}

/*function botaction_weather($message) {
	global $j;
	$from = $j->GetInfoFromMessageFrom($message);
	$body = $j->GetInfoFromMessageBody($message);

	$body_split = explode(" ", $body);
	foreach($body_split as $str) {
		if(preg_match("^\d{5}^", $str)) {
			$zip = $str;
		}
	}

	if(!isset($zip)) {
		$j->SendMessage($from, 'chat', null, array('body' => "I'm sorry, I could not understand the location you were looking for. Try saying \"weather zip\" where zip is your zip code."));
		return;
	}

	$j->SendMessage($from, 'chat', null, array('body'=>"Hang on, while I get your forcast for $zip."));

	//$weather_feed = file_get_contents("http://xml.weather.yahoo.com/forecastrss?p=$zip");
	//$weather_feed = file_get_contents("http://rss.weather.com/weather/rss/local/$zip?cm_ven=LWO&cm_cat=rss&par=LWO_rss");
	//echo "\n\n$weather_feed\n\n";
	
	//$rss = xml_parser_create_ns();

	//if(!xml_parse($rss, $weather_feed, true)) {
	//	echo "\n\n".xml_error_string(xml_get_error_code($rss))."\n\n";
	//	$j->SendMessage($from, 'chat', null, array("body"=>"There was an error accessing your forecast"));
	//	return;
	//}



	//$j->SendMessage($from, 'chat', null, array('body'=>"Here is your ".$rss->channel['description']));

	$rss = new XML_RSS("http://xml.weather.yahoo.com/forecastrss?p=$zip");

	var_dump($rss->getItems());

}*/


function botaction_welcome($message) {
	global $j;

	$from = $j->GetInfoFromMessageFrom($message);

	$j->SendMessage($from, 'chat', null, array('body'=>"Hello, I am Jabberish, a program to help you with everyday tasks. I was created by Mark Walling (markwalling@gmail.com)"));
}

function botaction_quit($message) {
	global $j, $bot_master;

	$from = $j->GetInfoFromMessageFrom($message);
	$jid = $j->StripJID($from);

	if($jid == $bot_master) {
		$j->SendMessage($bot_master, 'chat', null, array("body" => "Jabberish shutdown requested by $from"));
		$j->Disconnect();
		exit;
	}
	else {
		$j->SendMessage($from, 'chat', null, array("body" => "You are not authorized to issue that command."));
		$j->SendMessage($bot_master, 'chat', null, array("body" => "$from just tried to shut me down!!"));
	}
}


?>
